互億無(wú)線 · 文檔中心

語(yǔ)音通知 - 代碼示例


C++對(duì)接語(yǔ)音通知接口DEMO示例
本文為您提供了C++語(yǔ)言版本的語(yǔ)音通知接口對(duì)接DEMO示例

語(yǔ)音通知接口文檔 點(diǎn)擊下載

語(yǔ)音通知接口接入指南 點(diǎn)擊訪問(wèn)

//接口類型:互億無(wú)線語(yǔ)音通知接口。
// 賬戶注冊(cè):請(qǐng)通過(guò)該地址開(kāi)通賬戶https://user.ihuyi.com/new/register.html
// 注意事項(xiàng):
//(1)調(diào)試期間,請(qǐng)仔細(xì)閱讀接口文檔;
//(2)請(qǐng)使用APIID(查看APIID請(qǐng)登錄用戶中心->語(yǔ)音通知->產(chǎn)品總覽->APIID)及APIkey來(lái)調(diào)用接口;
//(3)該代碼僅供接入互億無(wú)線語(yǔ)音通知接口參考使用,客戶可根據(jù)實(shí)際需要自行編寫(xiě);

// DEMO僅作參考



#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <unistd.h>


#define SA struct sockaddr
#define MAXLINE 4096
#define MAXSUB  2000
#define MAXPARAM 2048
#define LISTENQ 1024

extern int h_errno;

int basefd;
char *hostname = "http://api.vm.ihuyi.com";
char *send_sms_uri = "/webservice/voice.php?method=Submit&format=json";

/**
* 發(fā)http post請(qǐng)求
*/
ssize_t http_post(char *page, char *poststr)
{
    char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
    ssize_t n;
    snprintf(sendline, MAXSUB,
        "POST %s HTTP/1.0\r\n"
        "Host: %s\r\n"
        "Content-type: application/x-www-form-urlencoded\r\n"
        "Content-length: %zu\r\n\r\n"
        "%s", page, hostname, strlen(poststr), poststr);

    write(basefd, sendline, strlen(sendline));
    while ((n = read(basefd, recvline, MAXLINE)) > 0) {
        recvline[n] = '\0';
        printf("%s", recvline);
    }
    return n;
}

/**
* 發(fā)送語(yǔ)音
*/
ssize_t send_voice(char *account, char *password, char *mobile, char *content)
{
    char params[MAXPARAM + 1];
    char *cp = params;
    sprintf(cp,"account=%s&password=%s&mobile=%s&content=%s", account, password, mobile, content);
    return http_post(send_sms_uri, cp);
}

int  socked_connect(char *arg)
{
    struct sockaddr_in their_addr = {0};  
    char buf[1024] = {0};  
    char rbuf[1024] = {0};  
    char pass[128] = {0};  
    struct hostent *host = NULL;   
    
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd<0)
    {
        printf ("create the sockfd is failed\n");
        return -1;
    }
    
    if((host = gethostbyname(arg))==NULL)  
    {  
        printf("Gethostname error, %s\n");  
        return -1; 
    }  
 
    memset(&their_addr, 0, sizeof(their_addr));  
    their_addr.sin_family = AF_INET;  
    their_addr.sin_port = htons(80);  
    their_addr.sin_addr = *((struct in_addr *)host->h_addr);
    if(connect(sockfd,(struct sockaddr *)&their_addr, sizeof(struct sockaddr)) < 0)  
    {  
        close(sockfd);
        return  -1;
    }  
    printf ("connect is success\n");
    return sockfd;
    
}

int main(void)
{
    struct sockaddr_in servaddr;
    char str[50];
    
    #if 0
    //建立socket連接
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_addr =*(hostname);
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(80);
    inet_pton(AF_INET, str, &servaddr.sin_addr);
    connect(sockfd, (SA *) & servaddr, sizeof(servaddr));
    #endif
    
    if((basefd= socked_connect(hostname))==-1)
    {
        printf("connect is failed\n");
        return -1;
    }
    printf("basefd is =%d\n",basefd);
    //用戶名是登錄用戶中心->語(yǔ)音通知->產(chǎn)品總覽->APIID
    char *account = "用戶名";

    //密碼 查看密碼請(qǐng)登錄用戶中心->語(yǔ)音通知->產(chǎn)品總覽->APIKEY
    char *password = "密碼";

    //手機(jī)號(hào)
    char *mobile = "138xxxxxxxx";

    //語(yǔ)音內(nèi)容
    char *content = "您的訂單號(hào)是:0648。已由順風(fēng)快遞發(fā)出,請(qǐng)注意查收。";

    /**************** 發(fā)送語(yǔ)音 *****************/
    send_voice(account, password, mobile, content);
    printf("send the message is success\n");
    close(basefd);
    exit(0);
}
語(yǔ)音通知接口
企業(yè)獨(dú)享外呼固話號(hào)碼;
多冗余線路、特色功能確保語(yǔ)音通知的高可靠和高呼通率。
24小時(shí)發(fā)送 失敗自動(dòng)重呼 企業(yè)獨(dú)享外呼號(hào)碼 語(yǔ)音+短信自動(dòng)雙呼 文本自動(dòng)轉(zhuǎn)語(yǔ)音
自助開(kāi)通語(yǔ)音通知免費(fèi)試用賬戶

現(xiàn)在注冊(cè),即享新用戶禮包!

在線咨詢
電話咨詢

服務(wù)熱線:

4008 808 898

服務(wù)熱線(工作時(shí)間):

4008 808 898

業(yè)務(wù)咨詢(非工作時(shí)間):

售后咨詢(非工作時(shí)間):

驗(yàn)證碼已發(fā)送到您的手機(jī),請(qǐng)查收!

輸入驗(yàn)證碼后,點(diǎn)擊“開(kāi)通體驗(yàn)賬戶”按鈕可立即開(kāi)通體驗(yàn)賬戶。

收不到短信驗(yàn)證碼?
互億無(wú)線不提供接碼服務(wù),接碼用戶請(qǐng)勿點(diǎn)擊開(kāi)通按鈕。
×